package com.example.traning.web.controller;

import com.example.traning.web.common.R;
import com.example.traning.web.config.MyKnife4jProperties;
import com.example.traning.web.controller.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * Apifox 工具测试
 * knife4j 文档地址：<a href="http://localhost:8080/doc.html">...</a>
 *
 * @author lei yu
 * @since 2025/04/27
 */
@Tag(name = "用户接口")
@RequestMapping("user")
@RestController
public class UserController {

    /**
     * <a href="http://localhost:8080/user/save">...</a>
     * {"id":"2","name":"李四"}
     */
    @Operation(summary = "保存用户")
    @PostMapping("save")
    public R retResult(@Valid @RequestBody UserVO vo) {
        System.out.println("保存成功 = " + vo);
        return R.ok(vo);
    }

    /**
     * <a href="http://localhost:8080/user/greet?name=Tom">...</a>
     */
    @GetMapping("/greet")
    public R greet(@RequestParam("name") String name) {

        return R.ok("Hello, " + name);
    }


    /**
     * <a href="http://localhost:8080/greet/1">...</a>
     */
    @GetMapping("/users/{id}")
    public R getUser(@PathVariable Long id) {
        // 根据id获取用户
        return R.ok(id);
    }


}
